/*
  Copyright (C) 2013 Napspirit / Thierry Rochelet

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.napspirit.tmx.ui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

import java.net.URL;

import com.napspirit.tmx.NapTMX;

public class LicenceDialog extends JDialog {

    

    public LicenceDialog() {
        this.initUI();
    }

    public final void initUI() {
        this.setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

        this.add(Box.createRigidArea(new Dimension(0, 10)));

        String licence = null;
        try {
            URL licenceURL = getClass().getResource(NapTMX.APPLICATION_LICENCE);
            BufferedReader in = new BufferedReader(new InputStreamReader(licenceURL.openStream()));
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = in.readLine()) != null) {
                sb.append(line);
            }
            
            in.close();
            licence = sb.toString();
        }
        catch (Exception e) {
            e.printStackTrace();
        }


        JLabel name = new JLabel(NapTMX.APPLICATION_NAME+" version "+NapTMX.APPLICATION_VERSION);
        name.setFont(new Font("Serif", Font.BOLD, 13));
        name.setAlignmentX(0.5f);
        this.add(name);

        this.add(Box.createRigidArea(new Dimension(0, 15)));

        name = new JLabel(licence);
        name.setFont(new Font("Serif", Font.PLAIN, 12));
        name.setAlignmentX(0.5f);
        this.add(name);

        this.add(Box.createRigidArea(new Dimension(0, 50)));

        JButton close = new JButton("Close");
        close.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) { dispose(); }
            });
        close.setAlignmentX(0.5f);
        add(close);

        this.setModalityType(ModalityType.APPLICATION_MODAL);

        this.setTitle("Licence "+NapTMX.APPLICATION_NAME);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setSize(400, 400);
    }
}
